package com.gh.rabbitmq.three;

import com.gh.rabbitmq.utils.RabbitmqUtils;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.MessageProperties;

import java.util.Scanner;

/**
 * @Author Eric
 * @Date 2021/7/17 18:26
 * @Version 1.0
 * 消息在手动应答时不丢失 放回队列中重新消费
 */
public class Task02 {

    public static final String TASK_QUEUE_NAME="ack_queue";

    public static void main(String[] args) throws Exception{
        Channel channel = RabbitmqUtils.getChannel();
        channel.queueDeclare(TASK_QUEUE_NAME,false,false,false,null);
        Scanner scanner=new Scanner(System.in);
        while (scanner.hasNext()){
            String message=scanner.nextLine();
            //设置生产者消息持久化 MessageProperties.PERSISTENT_TEXT_PLAIN
            channel.basicPublish("",TASK_QUEUE_NAME, MessageProperties.PERSISTENT_TEXT_PLAIN,message.getBytes());
            System.out.println("生产者发送消息:"+message);
        }
    }
}
